# -*- coding: ISO-8859-1 -*-
import random

class Composante():
    def __init__(self):
        self.niveauCpu=self.niveauComposanteAleatoire()
        self.niveauHdd=self.niveauComposanteAleatoire()
        self.Cpu=self.cpuAleatoire()
        self.Hdd=self.hddAleatoire()


    def upgraderCpu(self):
        self.niveauCpu = self.niveauCpu + 1
    
    
    
    
    
    def changerNiveauCpu(self,nouveauNiveauCpu):
        if self.validationNiveauCpu(nouveauNiveauCpu):
            self.niveauCpu=nouveauNiveauCpu
            return True
        else:
            return False
    
    def changerNiveauHdd(self,nouveauNiveauHdd):
        if self.validationNiveauHdd(nouveauNiveauHdd):
            self.niveauHdd=nouveauNiveauHdd
            return True
        else:
            return False
               
    def getNiveauCpu(self):
        return self.niveauCpu
    
    def getNiveauHdd(self):
        return self.niveauHdd  
    def getCPU(self):
        return self.Cpu   
    def getHdd(self):
        return self.Hdd
    def cpuAleatoire(self):
        r=random.randint(100,120)
        r/=100.0
        return (self.niveauCpu*r*100)
    def hddAleatoire(self):
        r=random.randint(100,120)
        r/=100.0
        return (self.niveauHdd*r*1000)
        
    def validationNiveauCpu(self,niveauVoulu):
        if ((niveauVoulu-1)==self.niveauCpu):
            return True
        else:
            return False
    
    def validationNiveauHdd(self,niveauVoulu):
        if ((niveauVoulu-1)==self.niveauHdd):
            return True
        else:
            return False
    
    def niveauComposanteAleatoire(self):
        r=random.randint(1,100)
        if r<=20:
            return 1
        elif r>20 and r<=40:
            return 2
        elif r>40 and r<=55:
            return 3
        elif r>55 and r<=68:
            return 4
        elif r>68 and r<=78:
            return 5
        elif r>78 and r<=86:
            return 6
        elif r>86 and r<=91:
            return 7
        elif r>91 and r<=96:
            return 8
        elif r>96 and r<=99:
            return 9
        elif r>99 and r<=100:
            return 10
        